
Imports System
Imports System.Collections
Imports System.Data
Imports System.Data.SqlClient
Imports _2bMatesSite.Common


Namespace _2bMatesSite.BO
	''' <summary>
	''' Summary description for Countries.
	''' </summary>
	Public Class Countries
		Public Const USAID As Integer = 220
		Public Const UKID As Integer = 218
		Public Const CANADAID As Integer = 36

		Protected list As ArrayList
		Protected hash As Hashtable

		Public Sub New()
			LoadCountries()
		End Sub

		Public ReadOnly Property List() As ArrayList
			Get
				Return list
			End Get
		End Property

		Public Function GetCountryByID(ByVal countryID As Integer) As Country
			Return DirectCast(hash(countryID), Country)
		End Function

		Protected Sub LoadCountries()
			list = New ArrayList()
			hash = New Hashtable()

			Dim conn As SqlConnection = DBManager.GetUnmanagedConnection()

			Try
				Dim cmd As New SqlCommand("SELECT * FROM Countries ORDER BY Country ASC")
				cmd.Connection = conn

				Dim dr As SqlDataReader = cmd.ExecuteReader()

				Dim ordID As Integer = dr.GetOrdinal("ID")
				Dim ordName As Integer = dr.GetOrdinal("Country")

				While dr.Read()
					Dim cnt As New Country(dr.GetInt32(ordID), dr.GetString(ordName))

					list.Add(cnt)
					hash(cnt.ID) = cnt
				End While

				dr.Close()
			Finally
				conn.Close()
			End Try
		End Sub

		Public Class Country
			Public ID As Integer
			Public Name As String

			Public Sub New(ByVal ID As Integer, ByVal Name As String)
				Me.ID = ID
				Me.Name = Name
			End Sub
		End Class
	End Class
End Namespace






